
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>


#define tc_log(_fmt_, ...)          printf("[TC][%s:%d][%s] "_fmt_"\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__)
#define tc_log_err(_fmt_, ...)      printf("[TC][ERR][%s:%d][%s] "_fmt_"\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__)

#define CountOfStrlen(a)   			(sizeof(a) / sizeof(*(a)) - 1)

#define Swap(a, b)          		do { a ^= b; b ^= a; a ^= b; } while (0)

static void hexdump(unsigned char *buf, int len, const char *str, ...)
{
	int i;

	va_list args;
 	va_start(args, str);
	vprintf(str, args);
	va_end(args);

	for (i = 0; i < len; ++i) {
		if (i % 16 == 0)
			printf("\n%p:", buf + i);
		printf(" %02x", buf[i]);
	}
	printf("\n");
}

static int c_atoi(const char c)
{
	if (c < '0' || c > '9')
		return -1;

	return c - '0';
}

int calc_days(int year, int month)
{
	switch (month) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
		return 31;

		case 4:
		case 6:
		case 9:
		case 11:
		return 30;

		case 2:
        if(year%4==0 && (year%100!=0 || year%400==0))
            return 29;
        else
            return 28;
	}
	return -1;
}

int main(int argc, char const *argv[])
{
	char str[32];
	int year, month, day, i, m, complete = 0;
	int total_days, mon_days;

	gets(str);
    for (i = 0; i < 4; ++i) {
        if (str[i] < '0' || str[i] > '9') {
            printf("%s\n", "Invalid input");
            return 0;
        }
    }
    for (i = 5; i < 7; ++i) {
        if (str[i] < '0' || str[i] > '9') {
            printf("%s\n", "Invalid input");
            return 0;
        }
    }
    for (i = 8; i < 10; ++i) {
        if (str[i] < '0' || str[i] > '9') {
            printf("%s\n", "Invalid input");
            return 0;
        }
    }
    
	str[4] = str[7] = str[10] = '\0';
	year = atoi(str);
	month = atoi(&str[5]);
	day = atoi(&str[8]);

	// scanf("%4d-%2d-%2d", &year, &month, &day);
	// printf("%d-%d-%d\n", year, month, day);

	if (year < 1990 || year > 9999 || month < 1 || month > 12 || day < 1) {
		printf("%s\n", "Invalid input");
		return 0;
	}

	if (day > calc_days(year, month)) {
		printf("%s\n", "Invalid input");
		return 0;
	}

	total_days = 0;
	for (i = 1990; i <= year; ++i) {
		for (m = 1; m <= 12; ++m) {

			// printf("%d-%d\n", i, m);
			mon_days = calc_days(i, m);
            if (mon_days <= 0) {
                printf("%s\n", "Invalid input");
		        return 0;
            }

			if (i == year && m == month) {
				total_days += day;

				complete = !0;
				break;
			} else {
				total_days += mon_days;
			}
		}

		if (complete)
			break;
	}

	printf("total_days %d\n", total_days);

	if ((total_days % 5) <= 3) {
		printf("%s\n", "He is working");
	} else {
		printf("%s\n", "He is having a rest");
	}

	return 0;
}


